package com.centaline.androidsalesblog.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.centanet.framework.glide.GlideLoad;
import com.orhanobut.logger.Logger;

/**
 * 网络状态变化
 * Created by guilin on 16/3/14.
 */
public class NetWorkChangeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        Logger.d("NetWorkChangeReceiver");
        if (networkInfo != null &&
                networkInfo.isConnected()) {
            GlideLoad.isWifi = networkInfo.getType() == 1;
        } else {
            GlideLoad.isWifi = false;
        }
    }
}
